#ifndef DYN_INTERPOLATION_H
#define DYN_INTERPOLATION_H

#include <armadillo>

using namespace arma;

/*! \author Joey Dumont
 *
 *  \date 2012-10-05
 *
 *  \brief Interpolation abstract class.
 *
 * We provide the basic functionality for
 * interpolation of data points. They need not
 * be equally spaced. Functions that return the
 * interpolated value at a point x is declared,
 * and methods for searching an ordered table are
 * put forward.
 *
 * This class relies heavily on the implementations
 * given in Numerical Recipes, 2007, W.H. Press et al, third
 * edition, chapter 3.
 */

class Interpolation
{
public:
    /*! The constructor paves the way
     * for the actual interpolation methods.
     * The \f$m\f$ represents the number of local points
     * used in the interpolation. */
    Interpolation(colvec _xValues,
                  colvec _yValues,
                  int _interPoints);

    /*! @name Accessor Functions */
    //@{
    colvec getXValues(){return xValues;}
    colvec getYValues(){return yValues;}
    int getInterpolationPoints(){return interPoints;}

    void setXValues(colvec _xValues){xValues=_xValues;}
    void setYValues(colvec _yValues){yValues=_yValues;}
    void setInterpolationPoints(int _interPoints){interPoints=_interPoints;}
    //@}

    /*! @name Table searching methods.  They return
     * the index of the nearest x value of the
     * given x value. */
    //@{
    /*! Bruteforce solution.  C++ realization
     * of Algorithm B of Section 6.2.1 of D.E. Knuth,
     * the Art of Computer Programming.*/
    int locate(const double x);
    /*! Bisection method. */
    int hunt(const double x);
    //@}

    /*! @name Interpolation Methods. */
    //@{
    /*! Given an x value, it returns the interpolate
     * value calculated by rawInterpolate(int,double).*/
    double interpolate(double x);
    /*! Pure virtual function that defines the actual interpolation method. */
    virtual double rawInterpolation(int _index, double x) = 0;
    //@}

protected:
    /*! @name Class Data */
    //@{
    colvec xValues;
    colvec yValues;
    int interPoints;
    int size;
    //@}

    /*! @name Determination of method to be used.
     * These variables are used to determine if we are to
     * use the locate(x) or hunt(x) methods. */
    //@
    int jsav;
    int correlation;
    int dj;
    //@}
};

#endif // DYN_INTERPOLATION_H
